package com.uniandes.edu.co.interfaz.interrupciones;

import java.awt.Dimension;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;

import com.uniandes.edu.co.dto.Ciclo;
import com.uniandes.edu.co.dto.Interrupcion;
import com.uniandes.edu.co.dto.Tsp;
import com.uniandes.edu.co.interfaz.mundo.Principal;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class EliminarInterrupcion extends javax.swing.JDialog {
	private Principal principal;
	private JLabel lblTitulo;
	private JLabel lblId;
	private JLabel lblDescripcion;
	private JTextField txtId;
	private JButton btnRegresar;
	private JButton btnEliminar;
	private JTextArea txtDescripcion;
	public LinkedList<Interrupcion> listadoI;
	private JLabel lblCiclo;
	private JComboBox jComboBox1;
	private JScrollPane jScrollPane1;
	/**
	* Auto-generated main method to display this JDialog
	*/
		
	public EliminarInterrupcion(Principal id) {
		super(id, true);
        principal = id;
        setTitle( "Eliminar Interrupcion" );
        initGUI();
	}
	
	private void initGUI() {
		try {
			listadoI = new LinkedList<Interrupcion>();
			{
				getContentPane().setLayout(null);
				{
					lblTitulo = new JLabel();
					getContentPane().add(lblTitulo);
					lblTitulo.setText("Eliminar Interrucion");
					lblTitulo.setBounds(167, 24, 119, 16);
					lblTitulo.setBounds(46, 18, 327, 29);
					lblTitulo.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
					lblTitulo.setFont(new java.awt.Font("Segoe UI",1,14));
					lblTitulo.setHorizontalAlignment(SwingConstants.CENTER);
					lblTitulo.setHorizontalTextPosition(SwingConstants.CENTER);
				}
				{
					lblId = new JLabel();
					getContentPane().add(lblId);
					lblId.setText("Id Interrupcion");
					lblId.setBounds(46, 96, 105, 19);
					lblId.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
				{
					lblDescripcion = new JLabel();
					getContentPane().add(lblDescripcion);
					lblDescripcion.setText("Descripcion");
					lblDescripcion.setBounds(46, 122, 105, 19);
					lblDescripcion.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
				{
					txtId = new JTextField();
					getContentPane().add(txtId);
					txtId.setBounds(157, 96, 216, 23);
					txtId.setText("");
				}
				jScrollPane1 = new JScrollPane();
				getContentPane().add(jScrollPane1);
				jScrollPane1.setBounds(157, 122, 216, 59);
				{
					txtDescripcion = new JTextArea();
					jScrollPane1.setViewportView(txtDescripcion);
					txtDescripcion.setText("");
					txtDescripcion.setBounds(157, 122, 216, 59);
					txtDescripcion.setText("");
				}
				{
					btnEliminar = new JButton();
					getContentPane().add(btnEliminar);
					btnEliminar.setText("Eliminar");
					btnEliminar.setBounds(46, 193, 130, 23);
					btnEliminar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							if(Tsp.getSingleton().eliminarInterrupcion(txtId.getText(),String.valueOf(jComboBox1.getSelectedItem())))
							{
								JOptionPane.showMessageDialog(null, "Su Interrupcion fue eliminada correctamente");
							}
							else
								JOptionPane.showMessageDialog(null, "No pudo eliminarse su Interrupcion");
						}
					});
				}
				{
					btnRegresar = new JButton();
					getContentPane().add(btnRegresar);
					btnRegresar.setText("Regresar");
					btnRegresar.setBounds(219, 194, 130, 23);
					btnRegresar.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							dispose();
						}
					});
				}
				{
					lblCiclo = new JLabel();
					getContentPane().add(lblCiclo);
					lblCiclo.setText("Ciclo");
					lblCiclo.setBounds(46, 64, 105, 16);
					lblCiclo.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
				}
				{
					List <Ciclo> ciclos=Tsp.getSingleton().getCiclos();
					List <Integer> idCiclos=new ArrayList<Integer>();
					for (Ciclo cic : ciclos) {
						idCiclos.add(cic.getIdCiclo());
					}
					ComboBoxModel jComboBox1Model = 
						new DefaultComboBoxModel(
								idCiclos.toArray());
					jComboBox1 = new JComboBox();
					getContentPane().add(jComboBox1);
					jComboBox1.setModel(jComboBox1Model);
					jComboBox1.setBounds(157, 64, 216, 23);
				}
			}
			this.setSize(430, 278);
			centrarVentana();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void centrarVentana(){
        Dimension dPantalla = Toolkit.getDefaultToolkit( ).getScreenSize( );
        Dimension dVentana = getSize( );

        int xEsquina = ( dPantalla.width / 2 ) - ( dVentana.width / 2 );
        int yEsquina = ( dPantalla.height / 2 ) - ( dVentana.height / 2 );

        setLocation( xEsquina, yEsquina );
    }
}
